const {
  getCurrentUserProfile,
  updateCurrentUserInfo,
  updateCurrentUserPassword,
  updateCurrentUserAvatar,
} = require("../service/profile");

module.exports = {
  async getUserInfo(ctx) {
    const result = await getCurrentUserProfile(ctx);

    ctx.body = {
      code: 0,
      message: "success",
      data: result,
    };
  },

  async updateUserInfo(ctx) {
    ctx.verifyParams({
      nickname: { type: "string", required: true },
    });

    await updateCurrentUserInfo(ctx, ctx.request.body);
    ctx.body = {
      code: 0,
      message: "success",
      data: true,
    };
  },

  async updatePassword(ctx) {
    ctx.verifyParams({
      oldPassword: { type: "string", required: true },
      newPassword: { type: "string", required: true },
    });

    await updateCurrentUserPassword(ctx, ctx.request.body);
    ctx.body = {
      code: 0,
      message: "success",
      data: true,
    };
  },

  async updateAvatar(ctx) {
    ctx.verifyParams({
      avatar: { type: "string", required: true },
    });

    await updateCurrentUserAvatar(ctx, ctx.request.body);
    ctx.body = {
      code: 0,
      message: "success",
      data: true,
    };
  },
};
